package com.ruoyi.activiti.controller;

import com.ruoyi.activiti.domain.dto.WorkflowTrajectory;
import com.ruoyi.activiti.service.impl.WorkflowTrajectoryService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 审批轨迹Controller
 *
 * @author ruoyi
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/workflow/trajectory")
public class WorkflowTrajectoryController extends BaseController
{
    @Autowired
    private WorkflowTrajectoryService workflowTrajectoryService;

    /**
     * 查询审批轨迹列表
     */
    //@PreAuthorize("@ss.hasPermi('system:activiti:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkflowTrajectory workflowTrajectory)
    {
        startPage();
        List<WorkflowTrajectory> list = workflowTrajectoryService.selectWorkflowTrajectoryList(workflowTrajectory);
        return getDataTable(list);
    }

    /**
     * 导出审批轨迹列表
     */
    //@PreAuthorize("@ss.hasPermi('system:activiti:export')")
    @Log(title = "审批轨迹", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkflowTrajectory workflowTrajectory)
    {
        List<WorkflowTrajectory> list = workflowTrajectoryService.selectWorkflowTrajectoryList(workflowTrajectory);
        ExcelUtil<WorkflowTrajectory> util = new ExcelUtil<WorkflowTrajectory>(WorkflowTrajectory.class);
        return util.exportExcel(list, "activiti");
    }

    /**
     * 获取审批轨迹详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:activiti:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(workflowTrajectoryService.selectWorkflowTrajectoryById(id));
    }

    /**
     * 新增审批轨迹
     */
    //@PreAuthorize("@ss.hasPermi('system:activiti:add')")
    @Log(title = "审批轨迹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkflowTrajectory workflowTrajectory)
    {
        return toAjax(workflowTrajectoryService.insertWorkflowTrajectory(workflowTrajectory));
    }

    /**
     * 修改审批轨迹
     */
    //@PreAuthorize("@ss.hasPermi('system:activiti:edit')")
    @Log(title = "审批轨迹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkflowTrajectory workflowTrajectory)
    {
        return toAjax(workflowTrajectoryService.updateWorkflowTrajectory(workflowTrajectory));
    }

    /**
     * 删除审批轨迹
     */
    //@PreAuthorize("@ss.hasPermi('system:activiti:remove')")
    @Log(title = "审批轨迹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(workflowTrajectoryService.deleteWorkflowTrajectoryByIds(ids));
    }
}
